package com.aynu.Contrller;

import com.aynu.entities.AnimationCharacter;
import com.aynu.entities.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
public class OrderController {

    public static final  String PAYMENT_URL = "http://localhost:8001";

    @Resource
    private RestTemplate restTemplate;

    //这里是get
    @GetMapping("/consumer/animation/create")
    public CommonResult<AnimationCharacter> create(AnimationCharacter animationCharacter){
        //传入地址  -- 传入类型 --返回类型
        System.out.println(animationCharacter);
        return restTemplate.postForObject(PAYMENT_URL+"/animation/creat",animationCharacter,CommonResult.class);
    }

    @GetMapping("/consumer/animation/get/{id}")
    public CommonResult<AnimationCharacter> getPayment(@PathVariable("id") Long id){
        //传入地址  -- 传入类型 --返回类型
        System.out.println("操得"+PAYMENT_URL);
        return restTemplate.getForObject(PAYMENT_URL + "/animation/get/"+id,CommonResult.class);
//return restTemplate.getForObject("http://localhost:8001/animation/get/1",CommonResult.class,8080);

    }

}
//httpClient两个服务之间调用
//
//restTemplate相当于对httpClient做了的一次封装，实现了order微服务和提供者微服务的横向连接